<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{padding: 0;margin: 0;}
        
        .box{
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;

            position: absolute;
            left:50px;
            top:50px;
        }
       
    </style>
</head>
<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    // 获取元素相对于父元素/包含块(定位)的偏移
    var box = document.getElementsByClassName("box")[0];
    console.dir(box);

    // 1.  获取非行内样式  => 自己算 => 麻烦
    // function getStyle(ele,cssKey){
    //     return getComputedStyle(ele)[cssKey];
    // }

    // console.log(parseInt(getStyle(box,"margin-left"))+parseInt(getStyle(box,"left")));
    // console.log(parseInt(getStyle(box,"margin-top"))+parseInt(getStyle(box,"top")));


    // 2. offsetLeft   offsetTop   左偏移/上偏移       => 获取元素相对于父元素/包含块(定位)的偏移 (margin和定位)
    // console.log(box.offsetLeft);
    // console.log(box.offsetTop);



</script>
</html>